package com.idroid.database;

import java.util.ArrayList;

import com.idroid.domain.AreaType;
import com.idroid.domain.ParkingArea;

import android.content.Context;
import android.database.SQLException;
import android.os.AsyncTask;

public class AreasByZipCodeAsyncTask extends
		AsyncTask<Void, Void, ArrayList<ParkingArea>> {

	Context ctx;
	int zipCode;
	private double maxPriceFilter;
	private boolean maxPriceFilterEnabled;
	private AreaType areaFilter;
	private boolean areaTypeFilterEnabled;

	public AreasByZipCodeAsyncTask(Context ctx, int zipCode,
			boolean maxPriceFilterEnabled, double maxPriceFilter,
			boolean areaTypeFilterEnabled, AreaType areaFilter) {
		this.ctx = ctx;
		this.zipCode = zipCode;
		this.maxPriceFilter = maxPriceFilter;
		this.maxPriceFilterEnabled = maxPriceFilterEnabled;
		this.areaFilter = areaFilter;
		this.areaTypeFilterEnabled = areaTypeFilterEnabled;
	}

	@Override
	protected ArrayList<ParkingArea> doInBackground(Void... params) {

		ArrayList<ParkingArea> parkingAreas = null;

		ParkingFlexDataSource source = new ParkingFlexDataSource(ctx);
		try {
			source.open();

			parkingAreas = source.getAreasByZipcode(zipCode + "",
					maxPriceFilterEnabled, maxPriceFilter,
					areaTypeFilterEnabled, areaFilter);

			System.out.println(zipCode + " " + parkingAreas.size());

			source.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			source.close();
			e.printStackTrace();
		}

		return parkingAreas;
	}

}
